<template lang="pug">
    div.kalix-article
        keep-alive
            el-row.frame-row(:gutter="10")
                el-col.frame-col(:span="8" )
                    kalix-org-tree(v-on:orgTreeClick="onOrgTreeClick")
                el-col.frame-col(:span="16")
                    kalix-table.duty-wrapper(ref="kalixBaseTable"
                    bizKey='duty' title='职务列表' v-bind:targetURL='targetURL'
                    v-bind:bizDialog='bizDialog' v-bind:btnList='btnList' v-bind:customRender="customRender"
                    v-bind:isFixedColumn="isFixedColumn" v-bind:dialogOptions="dialogOptions"
                    v-bind:buttonPermissionPrefix="buttonPermissionPrefix"
                    v-bind:toolbarBtnList="toolbarBtnList"
                    v-bind:customTableTool="customTableTool")
                        template(slot="tableColumnSlot")
                            el-table-column(prop="name"  label="职务名称")
                            el-table-column(prop="comment" label="职务描述")
                            el-table-column(prop="orgNameCol" label="组织机构")
                            el-table-column(prop="createBy" label="创建人")
                            kalix-date-column(prop="creationDate" label="创建日期")
</template>

<script>
  import {DutyButtonList, dutyBtnPermissionPrefix} from '../../config.toml'

  export default {
    name: 'kalix-admin-duty',
    watch: {},
    methods: {
      customTableTool(row, btnId, that) {
        switch (btnId) {
          case 'addUser': {
            // 增加用户
            that.whichBizDialog = ''
            let dig =
              that.bizDialog.filter((item) => {
                return item.id === 'addUser'
              })
            that.whichBizDialog = dig[0].dialog
            setTimeout(() => {
              that.$refs.kalixDialog.$refs.kalixBizDialog.open('添加用户', false, row)
            }, 20)
            break
          }
        }
      },
      onOrgTreeClick(data) {
        this.orgId = data.id
        this.orgName = data.name
        this.targetURL = `/camel/rest/orgs/${data.id}/dutys`
        this.dialogOptions = {
          orgId: this.orgId,
          orgName: this.orgName,
          targetURL: this.targetURL
        }
        console.log('org targetURL data is ', this.targetURL)
      },
      customRender(_data) {
        let that = this
        console.log('org _data data is ', _data)
        _data.forEach(function (e) {
          e.orgNameCol = that.orgName
        })
        console.log('org _data data is ', _data)
      }
    },

    data() {
      return {
        dialogOptions: {},
        isFixedColumn: true,
        btnList: DutyButtonList,
        targetURL: '',
        orgId: -1,
        orgName: '',
        bizDialog: [
          {id: 'view', dialog: 'AdminDutyView'},
          {id: 'edit', dialog: 'AdminDutyAdd'},
          {id: 'add', dialog: 'AdminDutyAdd'},
          {id: 'addUser', dialog: 'AdminDutyAddUser'}
        ],
        toolbarBtnList: [
          {id: 'add', isShow: true, title: '添加', isPermission: true}
        ],
        buttonPermissionPrefix: dutyBtnPermissionPrefix,
        tableHeight: 0 //  列表组件高度
        // bizSearch: 'AdminDutySearch'
      }
    },
    mounted() {
    },
    computed: {
      tableContainerStyle() {
        return {}
      }
    }
  }
</script>
